using System.Collections;
using System.Collections.Generic;
using QFramework;
using UnityEngine;

namespace AsterroidX
{
    public class GenerateScoreTextCmd : AbstractCommand
    {

        private Vector2 mPos2D;

        private string mText;

       private float textScales;

        public GenerateScoreTextCmd(Vector2 pos2D,string text, float textScales)
        {
            mPos2D = pos2D;
            mText = text;
            this.textScales = textScales;
        }
        protected override void OnExecute()
        {
            ResLoader resLoader = ResLoader.Allocate();

            var scoreText = resLoader.LoadSync<TextMesh>("resources://ScoreText");

            scoreText.Instantiate()
                  .Position2D(mPos2D)
                 .Self(self =>
                 {
                     self.text = mText;

                     var y = self.PositionY();

                     var targetY = y + 1f;

                     ActionKit
                        .Sequence()
                        .Lerp(0, 1f, 1f, (a) =>
                        {
                            self.PositionY(a.Lerp(y, targetY));

                            if (a <= 0.1f)
                            {
                                self.LocalScale((a / 0.1f * textScales).Lerp(0, 1));
                              
                            }
                        })
                        .StartCurrentScene(()=>self.DestroyGameObj());



                 });


        }
    }
}
